{{!

  Copyright (c) Facebook, Inc. and its affiliates.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

}}{{!

Pxd file to expose the interface defined in ClientsWrapper.h to CythonClients.pyx classes.

}}
{{> common/AutoGeneratedPy}}

from cpython.ref cimport PyObject
from libc.stdint cimport (
    int8_t as cint8_t,
    int16_t as cint16_t,
    int32_t as cint32_t,
    int64_t as cint64_t,
)
from libcpp cimport bool as cbool
from libcpp.map cimport map as cmap, pair as cpair
from libcpp.memory cimport shared_ptr, unique_ptr
from libcpp.set cimport set as cset
from libcpp.string cimport string
from libcpp.vector cimport vector

from folly cimport cFollyFuture, cFollyTry, cFollyUnit
cimport folly.iobuf as __iobuf
from thrift.py3.common cimport cRpcOptions

cimport {{#program:py3Namespaces}}{{value}}.{{/program:py3Namespaces}}{{program:name}}.types as _{{#program:py3Namespaces}}{{value}}_{{/program:py3Namespaces}}{{program:name}}_types
{{#program:has_stream?}}
from thrift.py3.stream cimport cResponseAndClientBufferedStream, cClientBufferedStream
{{/program:has_stream?}}

{{#program:includeNamespaces}}
{{#hasTypes?}}
cimport {{#includeNamespace}}{{value}}.{{/includeNamespace}}types as _{{#includeNamespace}}{{value}}_{{/includeNamespace}}types
{{/hasTypes?}}
{{#hasServices?}}
cimport {{#includeNamespace}}{{value}}.{{/includeNamespace}}clients_wrapper as _{{#includeNamespace}}{{value}}_{{/includeNamespace}}clients_wrapper
{{/hasServices?}}
{{/program:includeNamespaces}}

{{#program:services}}
cdef extern from "{{program:includePrefix}}gen-cpp2/{{service:name}}.h"{{!
    }} namespace "{{#program:cppNamespaces}}::{{value}}{{/program:cppNamespaces}}":
  cdef cppclass c{{service:name}}AsyncClient {{!
    }}"::{{#program:cppNamespaces}}{{value}}::{{/program:cppNamespaces}}{{!
    }}{{service:name}}AsyncClient":
      pass

cdef extern from "<utility>" namespace "std":
  cdef unique_ptr[c{{service:name}}ClientWrapper] move(unique_ptr[c{{service:name}}ClientWrapper])

{{/program:services}}
cdef extern from "thrift/lib/cpp/TProcessorEventHandler.h" namespace "::apache::thrift":
  cdef cppclass cTProcessorEventHandler "apache::thrift::TProcessorEventHandler":
    pass

cdef extern from "{{program:includePrefix}}gen-py3/{{program:name}}/clients_wrapper.h"{{!
    }} namespace "{{#program:cppNamespaces}}::{{value}}{{/program:cppNamespaces}}":{{!
    }}{{^program:services}}
  pass{{/program:services}}{{#program:services}}
  cdef cppclass c{{service:name}}ClientWrapper "{{!
  }}::{{#program:cppNamespaces}}{{value}}::{{/program:cppNamespaces}}{{service:name}}ClientWrapper"{{!
  }}{{#service:extends}}({{!
    }}{{#service:externalProgram?}}{{!
    }}_{{#service:py3Namespaces}}{{value}}_{{/service:py3Namespaces}}{{!
    }}{{service:programName}}_clients_wrapper.{{!
    }}{{/service:externalProgram?}}c{{service:name}}ClientWrapper{{!
  }}){{/service:extends}}:
    {{^service:extends?}}
    cFollyFuture[cFollyUnit] disconnect()
    void setPersistentHeader(const string& key, const string& value)
    void addEventHandler(const shared_ptr[cTProcessorEventHandler]& handler)
    {{/service:extends?}}

    {{#service:functions}}{{^function:returns_sink?}}
    cFollyFuture[{{#function:returnType}}{{> clients/CythonReturnTypeCppType}}{{/function:returnType}}] {{function:name}}(cRpcOptions, {{#function:args}}
      {{#field:type}}{{> types/CythonCppType}}{{/field:type}} arg_{{field:py_name}},{{/function:args}})
    {{/function:returns_sink?}}{{/service:functions}}
    {{!
      If this is an empty service definition that extends another service
      Then we need to put pass, otherwise cython will complain about the
      empty cppclass body
    }}
    {{^service:functions}}
    {{#service:extends?}}
    pass
    {{/service:extends?}}
    {{/service:functions}}

{{/program:services}}
